/*
 * TestEntities Class
 * The class is to test all models/entities class
 * All the object creatings test the constructor and the setters of a class
 * All the object showings test the toString and the getters of a class
 */

package tests;
import models.*;

/**
 *
 * @author tlnguyen
 */
public class TestEntities {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // try...

            // creating a contact => testing the constructor and all the setters
            Contact tlnguyen = new Contact("long", "192.168.1.1");
            // showing the contact => testing the toString method and all the getters
            System.out.println("One contact created. " + tlnguyen);

            // creating a message Hello to send
            Hello hello = new Hello(tlnguyen, false);
            // showing the message to send
            System.out.println("Send: \t" + hello);
            // converting the message into a bytearray to send
            byte[] byteHello = Message.toByteArray(hello);
            // sending...receiving...
            // getting the received message from a received byteArray
            Message message = Message.getMessage(byteHello, 0, byteHello.length);
            // testing what type of message it is
            if (message instanceof Hello){
                Hello helloRcvd = (Hello) message;
                System.out.println("Receive: \t" + helloRcvd);
            }

            //creating a message Chat to send
            Chat chat = new Chat(tlnguyen, "This is my first chatline.");
            // showing the message
            System.out.println("Send: \t"+ chat);
            // converting the message into a bytearray to send
            byte[] byteChat = Message.toByteArray(chat);
            // sending...receiving...
            // getting the received message from a received byteArray
            message = Message.getMessage(byteChat, 0, byteChat.length);
            // testing what type of message it is
            if (message instanceof Chat){
                Chat chatRcvd = (Chat) message;
                System.out.println("Receive: \t" + chatRcvd);
            }

            //creating a message Bye to send
            Bye bye = new Bye(tlnguyen);
            // showing the message
            System.out.println("Send: \t"+ bye);
            // converting the message into a bytearray to send
            byte[] byteBye = Message.toByteArray(bye);
            // sending...receiving...
            // getting the received message from a received byteArray
            message = Message.getMessage(byteBye, 0, byteBye.length);
            // testing what type of message it is
            if (message instanceof Bye){
                Bye byeRcvd = (Bye) message;
                System.out.println("Receive: \t" + byeRcvd);
            }
            
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("---- THE END ----");
    }

}
